<div class="content-wrapper">
    <section class="content-header">
        <h1>客保编辑</h1>
        <ol class="breadcrumb">
            <li><a href="/"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li class="active">公共配置</li>
            <li class="active">客保编辑</li>
        </ol>
    </section>
    <section class="content">
        <div class="box">
            <div class="box-header with-border">
            </div>
            <div class="box-body">
                <form class="form-horizontal" role="form" action="javascrip:;" method="post">
                    <input type="hidden" name="id" id="id" value="{$resInfo.id}" />
                    <div class="form-group">
                        <label for="title" class="col-sm-3 control-label"> 名称 </label>
                        <div class="col-sm-6">
                            <input class="form-control" id="title" name="title" value="{$resInfo.title}"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="status" class="col-sm-3 control-label"> 状态 </label>
                        <div class="col-sm-6">
                            <select class="form-control" id="status" name="status">
                                <option value="1" <if condition="$resInfo.status eq 1 ">selected</if>>开启</option>
                                <option value="2" <if condition="$resInfo.status eq 2 ">selected</if>>关闭</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="field_all" class="col-sm-3 control-label">验证字段</label>
                        <div class="col-sm-6">
                            <input id="field_all" type="hidden" name="field_all" value="{$resInfo.data}"/>
                            <div id="put_port_copy">
                                <label class="col-sm-pull-1">
                                    <input type="checkbox" name="field" class="minimal-red" value="company_name" <php>if(in_array('company_name', explode(',',$resInfo["data"]))):echo checked; endif;</php>>
                                    公司名称
                                </label>
                                <label class="col-sm-pull-1">
                                    <input type="checkbox" name="field" class="minimal-red" value="product_name" <php>if(in_array('product_name', explode(',',$resInfo["data"]))):echo checked; endif;</php>>
                                    产品名称
                                </label>
                                <label class="col-sm-pull-1">
                                    <input type="checkbox" name="field" class="minimal-red" value="name" <php>if(in_array('name', explode(',',$resInfo["data"]))):echo checked; endif;</php>>
                                    联系人
                                </label>
                                <label class="col-sm-pull-1">
                                    <input type="checkbox" name="field" class="minimal-red" value="mobile" <php>if(in_array('mobile', explode(',',$resInfo["data"]))):echo checked; endif;</php>>
                                    手机号
                                </label>
                                <label class="col-sm-pull-1">
                                    <input type="checkbox" name="field" class="minimal-red" value="tel" <php>if(in_array('tel', explode(',',$resInfo["data"]))):echo checked; endif;</php>>
                                    固话
                                </label>
                                <label class="col-sm-pull-1">
                                    <input type="checkbox" name="field" class="minimal-red" value="wechat" <php>if(in_array('wechat', explode(',',$resInfo["data"]))):echo checked; endif;</php>>
                                    微信
                                </label>
                                <label class="col-sm-pull-1">
                                    <input type="checkbox" name="field" class="minimal-red" value="qq" <php>if(in_array('qq', explode(',',$resInfo["data"]))):echo checked; endif;</php>>
                                    QQ
                                </label>
                                <label class="col-sm-pull-1">
                                    <input type="checkbox" name="field" class="minimal-red" value="cid" <php>if(in_array('cid', explode(',',$resInfo["data"]))):echo checked; endif;</php>>
                                    一级分类
                                </label>
                                <label class="col-sm-pull-1">
                                    <input type="checkbox" name="field" class="minimal-red" value="second_cid" <php>if(in_array('second_cid', explode(',',$resInfo["data"]))):echo checked; endif;</php>>
                                    二级分类
                                </label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="form-field-1" class="col-sm-3 control-label"></label>
                        <div class="col-sm-6">
                            <button type="button" class="btn btn-info btn-sm save-btn">提交</button>
                            &nbsp;
                            <button type="reset" class="btn btn-sm">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </section>
</div>
<script type="text/javascript">
    $(function () {
        $('input[type="checkbox"].minimal-red, input[type="radio"].minimal-red').iCheck({
            checkboxClass: 'icheckbox_minimal-red',
            radioClass: 'iradio_minimal-red'
        });
        //  投放端口
        $('input[name="field"]').on('ifChecked',function (event) {
            var strObj = $("#field_all").val();
            var strV = event.currentTarget.defaultValue;
            console.info(strObj);
            if(!strObj){
                strObj = new Array();
            }else {
                strObj = strObj.split(',')
            }
            strObj.push(strV);
            strObj.join(',');
            $("#field_all").val(strObj);
        }).on('ifUnchecked',function (event) {
            var strObj = $("#field_all").val();
            var strV = event.currentTarget.defaultValue;
            if(!strObj){
                strObj = new Array();
            }else {
                strObj = strObj.split(',')
            }
            strObj.splice($.inArray(strV, strObj), 1);
            strObj.join(',');
            $("#field_all").val(strObj);
        });
        //提交
        $(".save-btn").click(function () {
            var id = $("#id").val();
            var second_cid = $("#second_cid").val();
            var fields = $("#field_all").val();
            var title = $("#title").val();
            var status = $("#status").val();
            if(fields==''){
                ArtDialogHlp.showInfo('提示',"请选择字段");
                return false;
            }
            if(title==''){
                ArtDialogHlp.showInfo('提示',"请填写名称");
                return false;
            }
            $.post('/admin/CommonSet/ajaxSaveCommonSet',{
                id: id,
                title: title,
                second_cid: second_cid,
                status: status,
                data: fields
            },function (data) {
                if(data.Code == 999) {
                    ArtDialogHlp.showInfo('提示', '操作成功', function(){
                        window.location.reload(true)
                    });
                } else {
                    ArtDialogHlp.showInfo('提示', data.Msg);
                }
            },"JSON");
        })
    })
</script>